/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions.dispositivos;

import com.mapping.Dispositivo;
import com.mapping.Software;
import com.opensymphony.xwork2.ActionSupport;
import static com.opensymphony.xwork2.Action.SUCCESS;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
/**
 *
 * @author Andres
 */
@Namespace(value="/")
@Action(value="eliminarSoftwareDispositivo", results={@Result(name="success",location="/GestionDispositivos/rEliminarSoftwareDispositivo.jsp")})
public class EliminarSoftwareDispositivoAction extends ActionSupport{
    private String idDisp;
    private String idSoft;
    
    @Override
    public String execute(){
        String delete = "delete from soft_disp where idDisp=?1 and idSoft=?2";
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        Query query = em.createNativeQuery(delete);
        query.setParameter(1, idDisp);
        query.setParameter(2, idSoft);
        query.executeUpdate();
        tx.commit();
        em.close();
        
        return SUCCESS;
    }

    public void setIdDisp(String idDisp) {
        this.idDisp = idDisp;
    }

    public void setIdSoft(String idSoft) {
        this.idSoft = idSoft;
    }
}
